package com.gp.ssmplus.base.core.mybatis.model;


import com.gp.ssmplus.base.core.mybatis.common.utils.FlymeUtils;
import com.gp.ssmplus.base.core.mybatis.common.utils.JsonUtils;
import lombok.Data;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * update方法参数模型
 *
 * @author zyf
 * @date 2018/07/10
 */
@Data
public class UpdateModel {
    private Long id;
    private String handlerName;
    private String params;
    private Long[] fileIds;

    public UpdateModel(HttpServletRequest request) {
        Map maps = request.getParameterMap();
        Map<String, Object> params = new HashMap<>();
        for (Iterator iter = maps.entrySet().iterator(); iter.hasNext(); ) {
            Map.Entry element = (Map.Entry) iter.next();
            String strKey = element.getKey().toString();
            String[] strObj = (String[]) element.getValue();
            params.put(strKey, strObj[0]);
        }
        String json = JsonUtils.beanToJson(params);
        this.params = json;
    }

    public List<String> getBaseList() {
        String fields = "appId,nonce_str,_site_id_param,sessionKey,pageNo,pageSize,sign";
        List<String> strList = FlymeUtils.stringTolist(fields);
        return strList;
    }


    public static void main(String[] args) {
        String fields = "appId,nonce_str,_site_id_param,sessionKey,pageNo,pageSize,sign";
        List<String> strList = FlymeUtils.stringTolist(fields);
        boolean id = strList.contains("id");
        System.out.println(id);
    }
}
